/**
 * 用户相关 Mock 接口
 */

import Mock from 'mockjs'
import type { MockConfig } from '../server'

const userMocks: MockConfig[] = [
  // 用户登录
  {
    url: '/api/user/login',
    method: 'POST',
    response: (options: any) => {
      const { phone, password, code } = JSON.parse(options.body || '{}')
      
      // 测试账号验证
      const testPhone = '13800000000'
      const testPassword = 'test123'
      
      if (phone === testPhone && (password === testPassword || code === '123456')) {
        return {
          code: 200,
          msg: '登录成功',
          data: {
            token: Mock.Random.string('upper', 32),
            user: {
              id: 1,
              phone: phone,
              nickname: '测试用户',
              avatar: Mock.Random.image('100x100', Mock.Random.color(), '#FFF', 'Avatar'),
              is_vip: Mock.Random.boolean(),
              vip_expire_time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss')
            }
          }
        }
      }
      
      return {
        code: 401,
        msg: '账号或密码错误',
        data: null
      }
    }
  },

  // 获取用户信息
  {
    url: '/api/user/info',
    method: 'GET',
    response: () => {
      return {
        code: 200,
        msg: '获取成功',
        data: {
          id: 1,
          phone: '13800000000',
          nickname: '测试用户',
          avatar: Mock.Random.image('100x100', Mock.Random.color(), '#FFF', 'Avatar'),
          is_vip: true,
          vip_expire_time: '2024-12-31 23:59:59',
          created_at: '2024-01-01 00:00:00'
        }
      }
    }
  },

  // 发送验证码
  {
    url: '/api/user/send-code',
    method: 'POST',
    response: () => {
      return {
        code: 200,
        msg: '验证码已发送',
        data: {
          code: '123456' // 开发环境固定验证码
        }
      }
    }
  }
]

export default userMocks